/**
 * 模态框状态管理组合函数
 * 负责模态框的显示、隐藏和状态管理
 */
import { ref, computed } from 'vue';
import { smartTranslate as $t, transPlaceholder as $p } from '@/lang';

export function useModalState(props) {
  // 是否显示模态框
  const show = ref(false);

  // 当前激活的选项卡
  const activeTab = ref('basic');

  // 计算属性：模态框标题
  const modalTitle = computed(() => {
    return props.mode === 'add'
      ? $t('common.action.add')
      : $t('common.action.update');
  });

  /**
   * 显示模态框
   */
  const showModal = () => {
    show.value = true;
  };

  /**
   * 隐藏模态框
   */
  const hideModal = () => {
    show.value = false;
  };

  /**
   * 切换模态框显示状态
   */
  const toggleModal = () => {
    show.value = !show.value;
  };

  /**
   * 重置选项卡到基本信息
   */
  const resetActiveTab = () => {
    activeTab.value = 'basic';
  };

  return {
    show,
    activeTab,
    modalTitle,
    showModal,
    hideModal,
    toggleModal,
    resetActiveTab,
  };
}
